package com.pan.download5.factory.builder;

import com.pan.download5.config.entity.LineInfo;
import com.pan.download5.factory.DirectoryFactory;
import com.pan.download5.factory.PageFactory;
import com.pan.download5.factory.impl.AutoCrawlerDirectoryFactory;
import com.pan.download5.factory.impl.AutoCrawlerPageFactory;
import com.pan.download5.parse.AutoXmlParser;
import com.pan.download5.parse.entity.auto.impl.AutoDirectory;
import com.pan.download5.parse.entity.auto.impl.AutoPage;
import com.pan.download5.parse.entity.auto.impl.AutoTitle;

public class AutoAbstractFactory extends AbstractPageDirectoryFactory{

    private String pathName = "path";

    @Override
    public FactoryEntity createFactory(LineInfo lineInfo) {
        String path = getMapValue(lineInfo.getInfoMap(), pathName);

        AutoXmlParser autoXmlParser = new AutoXmlParser(path);
        AutoDirectory directoryInfo = autoXmlParser.getDirectory();
        AutoPage pageInfo = autoXmlParser.getPage();
        AutoTitle titleInfo = autoXmlParser.getTitle();

        DirectoryFactory directoryFactory = new AutoCrawlerDirectoryFactory(directoryInfo,titleInfo);
        PageFactory pageFactory = new AutoCrawlerPageFactory(pageInfo);

        return new FactoryEntity(directoryFactory, pageFactory);

    }
}
